package com.xidian.GMS.controller;


import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.mapper.EmploymentLawsAndRegulationsMapper;
import com.xidian.GMS.service.EmploymentLawsAndRegulationsService;

import javax.servlet.http.HttpSession;



@Controller
public class EmploymentLawsAndRegulationsController {
@Autowired
  private EmploymentLawsAndRegulationsMapper EmploymentLawsAndRegulationsMapper;
@Autowired
 private EmploymentLawsAndRegulationsService  EmploymentLawsAndRegulationsService;
@RequestMapping(value="/EmploymentLawsAndRegulationsEdit",method= RequestMethod.GET)
public String update0(int lawsid ,Model  model){
	    model.addAttribute("lawsid", lawsid);
		return "EmploymentLawsAndRegulationsEdit";
		// TODO: handle exception
	
}


@RequestMapping(value="/EmploymentLawsAndRegulationsEdit",method= RequestMethod.POST)
public String update(String lawsid, String title, String content){
	System.out.println(lawsid);
	int id = Integer.parseInt(lawsid);
	Date edittime = new Date();
		EmploymentLawsAndRegulationsService.update(id, title, content,edittime);
		return "EmploymentLawsAndRegulationsIndex";
}

@RequestMapping(value="/EmploymentLawsAndRegulationsInsert",method= RequestMethod.POST)
public String Insert(
		String title, String content){
	Date uploadtime = new Date();
	System.out.println(uploadtime);
	System.out.println(title);
	try {		
	    EmploymentLawsAndRegulationsService.Insert( title, uploadtime, content);
		return "EmploymentLawsAndRegulationsIndex";
	} catch (Exception e) {
		return "EmploymentLawsAndRegulationsInsert";
		// TODO: handle exception
	}
	
}
@RequestMapping(value="/EmploymentLawsAndRegulationsInsert",method= RequestMethod.GET)
public String Insert(){

		return "EmploymentLawsAndRegulationsInsert";
		// TODO: handle exception
	
	
}
@RequestMapping(value="/EmploymentLawsAndRegulations",method= RequestMethod.GET)
public String Insert22(){

		return "EmploymentLawsAndRegulations";
		// TODO: handle exception
	
	
}
@RequestMapping(value="/EmploymentLawsAndRegulationsDelete",method= RequestMethod.GET)
public String delete(int lawsid){
	try {
	    EmploymentLawsAndRegulationsService.delete(lawsid);
		return "forward:/fun1-employmentLawsAndRegulations.html";
	} catch (Exception e) {
		return "EmploymentLawsAndRegulationsInsert";
		// TODO: handle exception
	}
	
}

@RequestMapping(value="/EmploymentLawsAndRegulationsIndex",method= RequestMethod.POST)
public String IndexPost(){

		return "EmploymentLawsAndRegulationsIndex";
		// TODO: handle exception
	}
	

@RequestMapping(value="/EmploymentLawsAndRegulationsIndex",method= RequestMethod.GET)
@ResponseBody
public Page InsertGet(@RequestParam(name="cur", defaultValue="1") int cur, Model model){
	Page page = EmploymentLawsAndRegulationsService.getEmploymentLawsAndRegulations(cur);
	System.out.println(page);
 	model.addAttribute("page", page);
	
	
		return page;
		// TODO: handle exception
	
	
}


}
